package com.swh.cloud.biz.ui.conf;

import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.netflix.ribbon.RibbonClient;
import org.springframework.cloud.netflix.ribbon.RibbonClientConfiguration;
import org.springframework.cloud.netflix.ribbon.RibbonClients;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.netflix.client.config.IClientConfig;
import com.netflix.loadbalancer.ConfigurationBasedServerList;
import com.netflix.loadbalancer.Server;
import com.netflix.loadbalancer.ServerList;

/**
 * 配置ribbon的一些参数信息(包括负载均衡算法)
 * 在这里我们可以重写任何ribbon相关的一些bean,只需要把方法名写的和Spring Cloud Netflix提供的方法名一样就可以
 * @author sangwenhao-桑文豪
 * @date 2017年1月8日 下午8:23:50
 */
//@Configuration
//@ConfigurationProperties
//@EnableAutoConfiguration
//@PropertySource("classpath:config.properties")
public class MyDefaultRibbonConfiguration extends RibbonClientConfiguration {
	
	private static final Logger logger = LoggerFactory.getLogger(MyDefaultRibbonConfiguration.class);
	@Bean
    @Override
    public ServerList<Server> ribbonServerList(IClientConfig clientConfig) {
        ConfigurationBasedServerList serverList = new ConfigurationBasedServerList();
        logger.info(">>>>>>>>serverList:"+ReflectionToStringBuilder.toString(serverList.getInitialListOfServers()));
        serverList.initWithNiwsConfig(clientConfig);
        return serverList;
    }
}
